|
|
|
|
|
|
|
access it like an array, as in the following line of code, which sets a form's picture to the first image in an ImageList control: |
|
|
|
|
|
|
|
|
Set form1.Picture = ImageList1.ListImages(1).Picture |
|
|
|
|
|
|
|
|
Notice that a specific object is referred to with its indexin this case, 1. Remember, a collection stores objects, unlike an array, which stores values. These objects, in turn, have their own set of properties. |
|
|
|
|
|
|
|
|
One special property that objects in a collection have is the Key property. An object's key is a text string that can be used in the same manner as an index: |
|
|
|
|
|
|
|
|
Set form1.Picture = ImageList1.ListImages("Smiley Face").Picture |
|
|
|
|
|
|
|
|
To use a key to look up an object in a collection, you have to specify it when the object is added to the collection. Each type of collection has defined Add and Remove methods, which include Key and Index as parameters. If the index is omitted, it is supplied by Visual Basic. The key, however, is optional. |
|
|
|
|
|
|
|
|
The ListView and TreeView controls allow you to organize data for viewing in a manner similar to that used by the Windows Explorer (see Figure 12.4). The great thing about these controls is that they effectively separate the controls' appearance from the data contained in the controls. For example, consider a list of 100 items. Using the ListView, you can sort these items and change the way they are viewed by simply setting properties of the control. This is a great improvement over a standard list box, in which rearranging items means reloading the list box. |
|
|
|
|
|
|
|
|
Figure 12.4
Windows Explorer makes use of both a TreeView
interface (left pane) and a ListView interface (right pane). |
|
|
|
|
|
|
|
|
In the following section, you create sample ListView and TreeView projects. Keep in mind that they are tricky controls to master. You might want to spend a little time going over the online help files to get a good grounding in their use. Your time will be well spent. |
|
|
|
|
|